try:
    print(1/0)
except ZeroDivisionError: #表示只接受ZeroDivisionError异常
    print("Error: Division by zero is not allowed")

try:
    print(1/0)
except Exception as e: #表示会接受所有异常
    print(e)

try:
    print(1/0)
except ZeroDivisionError as e:
    print("Error:", e)
else:
    print("success")

try:
    print(1/1)
except ZeroDivisionError as e:
    print("Error:", e)
else:
    print("success") #当try中的代码没有异常时，会执行else中的代码

try:
    print(1/0)
except Exception as e:
    print("Error:", e)
finally:
    print("This will always be executed") #无论try中的代码是否有异常，都会执行finally中的代码


#自定义异常，将异常进行抛出，相当于java的throw，py使用raise
try:
    raise Exception("This is a custom exception") #抛出异常
except Exception as e:
    print(e)